package com.xnx.bincker.leader.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import java.util.List;

/**
 * 返回前端的Page类
 * @param <T>
 */
@JsonIgnoreProperties(value = {"first", "last", "number", "numberOfElements", "pageable", "size", "sort", "totalElements", "totalPages"})
public class CustomPage<T> extends PageImpl<T> {
    public CustomPage(List<T> content, Pageable pageable, long total) {
        super(content, pageable, total);
    }

    public CustomPage(List<T> content) {
        super(content);
    }

    public CustomPage(Page<T> page){
        super(page.getContent(), page.getPageable(), page.getTotalElements());
    }

    /**
     * 页码
     */
    public int getPage(){
        return this.getNumber();
    }

    /**
     * 数据总数
     */
    public long getTotal(){
        return this.getTotalElements();
    }

    /**
     * 数据列表
     */
    @Override
    public List<T> getContent() {
        return super.getContent();
    }
}
